package scan

import (
	"time"
)

type ScanPortResult struct {
	Open             bool
	ResponseDuration time.Duration
}

func NewScanPortResult(open bool, duration time.Duration) *ScanPortResult {
	return &ScanPortResult{
		Open:             open,
		ResponseDuration: duration,
	}
}

type IPAndPort struct {
	IP   string
	Port int
}

func NewIPAndPort(ip string, port int) *IPAndPort {
	return &IPAndPort{
		IP:   ip,
		Port: port,
	}
}

type DomainRecord struct {
	DNSv6 []*IPAndPort
	DNSv4 []*IPAndPort
}

func NewDomainRecord() *DomainRecord {
	return &DomainRecord{
		DNSv6: []*IPAndPort{},
		DNSv4: []*IPAndPort{},
	}
}

func (d *DomainRecord) AddV4(ip *IPAndPort) *DomainRecord {
	d.DNSv4 = append(d.DNSv4, ip)
	return d
}
func (d *DomainRecord) AddV6(ip *IPAndPort) *DomainRecord {
	d.DNSv6 = append(d.DNSv6, ip)
	return d
}

type IPAndDuration struct {
	IP               string
	ResponseDuration time.Duration
}

func NewIPAndDuration(ip string, duration time.Duration) *IPAndDuration {
	return &IPAndDuration{
		IP:               ip,
		ResponseDuration: duration,
	}
}

type IPAndDurationAndOpen struct {
	Open bool
	*IPAndDuration
}

func NewIPAndDurationAndOpen(ip string, duration time.Duration, open bool) *IPAndDurationAndOpen {
	return &IPAndDurationAndOpen{
		Open:          open,
		IPAndDuration: NewIPAndDuration(ip, duration),
	}
}

type IPsAndDuration struct {
	IPv4 []*IPAndDurationAndOpen
	IPv6 []*IPAndDurationAndOpen
}

func NewIPsAndDuration() *IPsAndDuration {
	return &IPsAndDuration{
		IPv4: []*IPAndDurationAndOpen{},
		IPv6: []*IPAndDurationAndOpen{},
	}
}

func (i *IPsAndDuration) AddV4(ip *IPAndDurationAndOpen) {
	i.IPv4 = append(i.IPv4, ip)
}
func (i *IPsAndDuration) AddV6(ip *IPAndDurationAndOpen) {
	i.IPv6 = append(i.IPv6, ip)
}

type PortRes struct {
	OK bool
	IP string
}

func NewPortRes() *PortRes {
	return &PortRes{
		OK: false,
		IP: "",
	}
}

type BestPortRecord struct {
	DNSv6 *PortRes
	DNSv4 *PortRes
}

func NewBestPortRecord() *BestPortRecord {
	return &BestPortRecord{
		DNSv6: NewPortRes(),
		DNSv4: NewPortRes(),
	}
}
